<?php

namespace XiaoZhuBundle\Controller;

use AdminsBundle\Entity\Product;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use XiaoZhuBundle\Helper\MyController;

class DefaultController extends MyController
{
    /**
     * @Route("/", name="shophome")
     */
    public function indexAction()
    {
        //首页数据获取
        $ProductModel = $this->get("xiao_zhu.product_model");

        //最新商品
        $param = array();
        $param["andWhere"]["isNew"] = 1;
        $param["page"] = 1;
        $param["per_page"] = 10;
        $ProductNew = $ProductModel->listProduct($param);
        $data["ProductNew"] = $ProductNew;

        //饰品心情
        $artClass = 1;
        $MaxCount = 8;
        $Art1 = $this->DB("AdminsBundle:Article")->getIndexList($artClass,$MaxCount);
        $data["Art1"] = $Art1;

        //品牌活动：待定
        //商城特惠：待定

        $ProductModel = $this->get("xiao_zhu.product_model");
        //项链
        $param = array();
        $param["andWhere"]["cid"] = 2;
        $param["andWhere"]["cid"] = 1;//todo
        $param["page"] = 1;
        $param["per_page"] = 16;
        $Neck = $ProductModel->listProduct($param);
        //todo 产品熟练够足够的时候，以下代码应该删除
        $count = count($Neck);
        for ($i = 0;$i<$count%4;$i++) {
            unset($Neck[$i]);
        }
        $data["Neck"] = $Neck;

        //耳饰
        $param = array();
        $param["andWhere"]["cid"] = 3;
        $param["andWhere"]["cid"] = 1;//todo
        $param["page"] = 1;
        $param["per_page"] = 16;
        $Ear = $ProductModel->listProduct($param);
        //todo 产品熟练够足够的时候，以下代码应该删除
        $count = count($Ear);
        for ($i = 0;$i<$count%4;$i++) {
            unset($Ear[$i]);
        }
        $data["Ear"] = $Ear;

        //发饰
        $param = array();
        $param["andWhere"]["cid"] = 4;
        $param["andWhere"]["cid"] = 1;//todo
        $param["page"] = 1;
        $param["per_page"] = 16;
        $Hair = $ProductModel->listProduct($param);
        //todo 产品熟练够足够的时候，以下代码应该删除
        $count = count($Hair);
        for ($i = 0;$i<$count%4;$i++) {
            unset($Hair[$i]);
        }
        $data["Hair"] = $Hair;

        //////////////////////////////////////////////////////////////////////////////

        $slider = array(
            'layer1'=>'bundles/xiaozhu/temp/sliders/slide1/bg.jpg',
            'layer2'=>'bundles/xiaozhu/temp/sliders/slide2/bg.jpg',
            'layer3'=>'bundles/xiaozhu/temp/sliders/slide3/bg.jpg',
            'layer4'=>'bundles/xiaozhu/temp/sliders/slide4/bg.jpg'
        );
        $data['slider']=$slider;

        $home_cat = array('cat2'=>'bundles/xiaozhu/temp/cat/item2.png',
            'cat3'=>'bundles/xiaozhu/temp/cat/item3.png',
            'cat4'=>'bundles/xiaozhu/temp/cat/item4.png',
            'cat5'=>'bundles/xiaozhu/temp/cat/item5.png',
            'cat6'=>'bundles/xiaozhu/temp/cat/item6.png');
        $data['home_cat'] = $home_cat;


        return $this->render('@XiaoZhu/homepage.html.twig',$data);
    }


}
